Imports Clo = Enhancements.Core.Logging
Imports Gen = System.Collections.Generic
Imports Glo = System.Globalization
Imports Ref = System.Reflection
Imports Sys = System
Imports Val = Enhancements.Basic.Expressions.Values

Namespace Enhancements.Basic.Expressions
    <Serializable(), DebuggerStepThrough()> _
    Friend NotInheritable Class ___Identifiers

        Private Sub New()
        End Sub

        ''' <exception cref="IsNullException"> </exception>
        ''' <exception cref="IsEmptyException"> </exception>
        ''' <exception cref="IdentifierIsValidNotException"> </exception>
        Friend Shared Function AssertIsValid(ByVal _string As System.String, ByVal _throwException As System.Boolean) As System.Boolean
            _string.IsEmptyNot("_string", True)

            Dim _returnValue As System.Boolean = False
            If _string.Length.IsInRange("_string.Length", 1, 1, False) Then
                If ___Texts.StartsWithStandardLetter(_string) Then
                    _returnValue = True
                End If
            Else
                If ___Texts.StartsWithStandardLetter(_string) Or ___Texts.StartsWithUnderscore(_string) Then
                    If ___Texts.ContainsOnlyStandardLettersAndStandardDigitsAndUnderscores(_string.Substring(1)) Then
                        If ___Texts.ContainsAtLeastOneStandardLetterOrStandardDigit(_string) Then
                            _returnValue = True
                        End If
                    End If
                End If
            End If
            If Not _returnValue And _throwException Then
                IdentifierIsValidNotException.___Throw(_string)
            End If

            Return _returnValue
        End Function

        ''' <exception cref="IsNullException"> </exception>
        ''' <exception cref="IsListFilledNotException"> </exception>
        ''' <exception cref="IsEmptyException"> </exception>
        ''' <exception cref="IdentifiersAreValidNotException"> </exception>
        Friend Shared Function AssertAreValid(ByVal _strings() As System.String, ByVal _throwException As System.Boolean) As System.Boolean
            _strings.IsListFilled("_strings", True)

            Dim _returnValue As System.Boolean = True
            For Each _string As System.String In _strings
                If Not AssertIsValid(_string, False) Then
                    _returnValue = False
                    Exit For
                End If
            Next _string
            If Not _returnValue And _throwException Then
                IdentifiersAreValidNotException.___Throw(_strings)
            End If

            Return _returnValue
        End Function

        ''' <exception cref="IsNullException"> </exception>
        ''' <exception cref="IsListFilledNotException"> </exception>
        ''' <exception cref="IsEmptyException"> </exception>
        ''' <exception cref="IdentifiersAreValidNotException"> </exception>
        ''' <exception cref="IdentifiersAreValidAndRepeatedException"> </exception>
        Friend Shared Function AssertAreValidAndRepeatedNot(ByVal _strings() As String, ByVal _throwException As System.Boolean) As System.Boolean
            AssertAreValid(_strings, True)

            Dim _returnValue As System.Boolean = True
            Dim _stringsList As Gen.List(Of System.String) = New Gen.List(Of System.String)()
            For Each _string As System.String In _strings
                If _stringsList.Contains(___Texts.ToUpper(_string)) Then
                    _returnValue = False
                    Exit For
                Else
                    _stringsList.Add(___Texts.ToUpper(_string))
                End If
            Next _string
            If Not _returnValue And _throwException Then
                IdentifiersAreValidAndRepeatedException.___Throw(_strings)
            End If

            Return _returnValue
        End Function

        ''' <exception cref="IsNullException"> </exception>
        ''' <exception cref="IsListFilledNotException"> </exception>
        ''' <exception cref="IdentifiersAreRepeatedException"> </exception>
        Friend Shared Function AssertAreRepeatedNot(ByVal _strings() As String, ByVal _throwException As System.Boolean) As System.Boolean
            _strings.IsListFilled("_strings", True)

            Dim _returnValue As System.Boolean = True
            Dim _stringsList As Gen.List(Of System.String) = New Gen.List(Of System.String)()
            For Each _string As System.String In _strings
                If _stringsList.Contains(___Texts.ToUpper(_string)) Then
                    _returnValue = False
                    Exit For
                Else
                    _stringsList.Add(___Texts.ToUpper(_string))
                End If
            Next _string
            If Not _returnValue And _throwException Then
                IdentifiersAreRepeatedException.___Throw(_strings)
            End If

            Return _returnValue
        End Function

    End Class
End Namespace
